import "reflect-metadata";

export function Autowired(injectid?: string): PropertyDecorator {
  return (targetClassPrototype, propertyKey) => {
    let getInstance: any;
    const metaSignleton = Reflect.getMetadata(
      "signleton",
      targetClassPrototype,
      propertyKey
    );
    const getClassOrInstance = Reflect.getMetadata(
      "getClassOrInstance",
      targetClassPrototype,
      propertyKey
    );
    if (metaSignleton) {
      // console.log("我是单例");
      getInstance = getClassOrInstance;
    } else {
      getInstance = new getClassOrInstance();
    }

    Reflect.defineProperty(targetClassPrototype, propertyKey, {
      value: getInstance,
      configurable: true,
      writable: true
    });
  };
}

/* export default function Autowired(
  injectid?: string,
  singleton?: boolean
): PropertyDecorator {
  return (targetClassPrototype, propertyKey) => {
    let PropClass = Reflect.getMetadata(
      "design:type",
      targetClassPrototype,
      propertyKey
    );
    // console.log(PropClass);
    const getStaticMethod = PropClass.getServiceImplClass();
    let getInstance: any;
    if (singleton) {
      getInstance = getStaticMethod.getInstance();
    } else {
      getInstance = new getStaticMethod();
    }
    // let PropClassObj = new getStaticMethod();

    Reflect.defineProperty(targetClassPrototype, propertyKey, {
      value: getInstance,
      configurable: true,
      writable: true
    });
  };
} */
